package com.mytest.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AopAspect {

    @Pointcut("execution(* com.mytest.service..*.*(..))")
    public void pointcut(){}

    @Around("pointcut()")
    public void aroundAdvice(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("--before--");
            Object result = joinPoint.proceed(); //目标对象方法的执行
            System.out.println("--after--");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("--exception--");
        } finally {
            System.out.println("--finally--");
        }
    }
}
